from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-16 14:02:32.086356
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 16, Jun, 2022
Time: 14:02:39
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5312
Nobs: 689.000 HQIC: -49.8944
Log likelihood: 8558.73 FPE: 1.70459e-22
AIC: -50.1236 Det(Omega_mle): 1.49727e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.302270 0.058550 5.163 0.000
L1.Burgenland 0.106212 0.038206 2.780 0.005
L1.Kärnten -0.109685 0.020191 -5.432 0.000
L1.Niederösterreich 0.203022 0.079971 2.539 0.011
L1.Oberösterreich 0.106343 0.078261 1.359 0.174
L1.Salzburg 0.257521 0.040835 6.306 0.000
L1.Steiermark 0.047460 0.053446 0.888 0.375
L1.Tirol 0.109433 0.043173 2.535 0.011
L1.Vorarlberg -0.053714 0.037461 -1.434 0.152
L1.Wien 0.036119 0.069225 0.522 0.602
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055856 0.123302 0.453 0.651
L1.Burgenland -0.036861 0.080458 -0.458 0.647
L1.Kärnten 0.041241 0.042521 0.970 0.332
L1.Niederösterreich -0.180330 0.168414 -1.071 0.284
L1.Oberösterreich 0.432031 0.164813 2.621 0.009
L1.Salzburg 0.287507 0.085997 3.343 0.001
L1.Steiermark 0.105504 0.112555 0.937 0.349
L1.Tirol 0.316382 0.090919 3.480 0.001
L1.Vorarlberg 0.029818 0.078889 0.378 0.705
L1.Wien -0.043928 0.145783 -0.301 0.763
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188368 0.029971 6.285 0.000
L1.Burgenland 0.089119 0.019557 4.557 0.000
L1.Kärnten -0.007719 0.010336 -0.747 0.455
L1.Niederösterreich 0.259219 0.040936 6.332 0.000
L1.Oberösterreich 0.139391 0.040061 3.479 0.001
L1.Salzburg 0.045743 0.020903 2.188 0.029
L1.Steiermark 0.023979 0.027359 0.876 0.381
L1.Tirol 0.090105 0.022100 4.077 0.000
L1.Vorarlberg 0.058555 0.019176 3.054 0.002
L1.Wien 0.114394 0.035436 3.228 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109498 0.030344 3.609 0.000
L1.Burgenland 0.044318 0.019800 2.238 0.025
L1.Kärnten -0.013963 0.010464 -1.334 0.182
L1.Niederösterreich 0.186184 0.041445 4.492 0.000
L1.Oberösterreich 0.306278 0.040559 7.551 0.000
L1.Salzburg 0.104855 0.021163 4.955 0.000
L1.Steiermark 0.109383 0.027699 3.949 0.000
L1.Tirol 0.102517 0.022374 4.582 0.000
L1.Vorarlberg 0.070449 0.019414 3.629 0.000
L1.Wien -0.020375 0.035876 -0.568 0.570
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132135 0.055787 2.369 0.018
L1.Burgenland -0.050384 0.036402 -1.384 0.166
L1.Kärnten -0.044956 0.019238 -2.337 0.019
L1.Niederösterreich 0.149872 0.076197 1.967 0.049
L1.Oberösterreich 0.143078 0.074568 1.919 0.055
L1.Salzburg 0.284098 0.038908 7.302 0.000
L1.Steiermark 0.052826 0.050924 1.037 0.300
L1.Tirol 0.167740 0.041135 4.078 0.000
L1.Vorarlberg 0.098252 0.035693 2.753 0.006
L1.Wien 0.069740 0.065958 1.057 0.290
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059060 0.044007 1.342 0.180
L1.Burgenland 0.033075 0.028716 1.152 0.249
L1.Kärnten 0.051092 0.015176 3.367 0.001
L1.Niederösterreich 0.207956 0.060107 3.460 0.001
L1.Oberösterreich 0.297583 0.058822 5.059 0.000
L1.Salzburg 0.044115 0.030692 1.437 0.151
L1.Steiermark 0.008884 0.040171 0.221 0.825
L1.Tirol 0.138121 0.032449 4.257 0.000
L1.Vorarlberg 0.075824 0.028156 2.693 0.007
L1.Wien 0.084949 0.052030 1.633 0.103
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170277 0.052899 3.219 0.001
L1.Burgenland -0.001432 0.034519 -0.041 0.967
L1.Kärnten -0.063724 0.018243 -3.493 0.000
L1.Niederösterreich -0.087301 0.072253 -1.208 0.227
L1.Oberösterreich 0.196734 0.070708 2.782 0.005
L1.Salzburg 0.055064 0.036895 1.492 0.136
L1.Steiermark 0.243510 0.048288 5.043 0.000
L1.Tirol 0.497852 0.039006 12.763 0.000
L1.Vorarlberg 0.049409 0.033845 1.460 0.144
L1.Wien -0.057861 0.062544 -0.925 0.355
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158475 0.060045 2.639 0.008
L1.Burgenland -0.012731 0.039181 -0.325 0.745
L1.Kärnten 0.063441 0.020707 3.064 0.002
L1.Niederösterreich 0.198702 0.082014 2.423 0.015
L1.Oberösterreich -0.072533 0.080260 -0.904 0.366
L1.Salzburg 0.207354 0.041878 4.951 0.000
L1.Steiermark 0.138897 0.054812 2.534 0.011
L1.Tirol 0.064706 0.044275 1.461 0.144
L1.Vorarlberg 0.123555 0.038417 3.216 0.001
L1.Wien 0.132717 0.070993 1.869 0.062
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.368593 0.034881 10.567 0.000
L1.Burgenland 0.005097 0.022761 0.224 0.823
L1.Kärnten -0.023537 0.012029 -1.957 0.050
L1.Niederösterreich 0.216125 0.047643 4.536 0.000
L1.Oberösterreich 0.204306 0.046624 4.382 0.000
L1.Salzburg 0.043398 0.024328 1.784 0.074
L1.Steiermark -0.016921 0.031841 -0.531 0.595
L1.Tirol 0.105856 0.025720 4.116 0.000
L1.Vorarlberg 0.069665 0.022317 3.122 0.002
L1.Wien 0.029488 0.041241 0.715 0.475
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037105 0.130709 0.189326 0.150994 0.112170 0.094781 0.052332 0.216516
Kärnten 0.037105 1.000000 -0.017321 0.132774 0.055340 0.092024 0.437337 -0.055693 0.092613
Niederösterreich 0.130709 -0.017321 1.000000 0.333788 0.139310 0.292077 0.084568 0.171228 0.310626
Oberösterreich 0.189326 0.132774 0.333788 1.000000 0.223819 0.318272 0.169796 0.153306 0.262978
Salzburg 0.150994 0.055340 0.139310 0.223819 1.000000 0.136062 0.110267 0.133786 0.131685
Steiermark 0.112170 0.092024 0.292077 0.318272 0.136062 1.000000 0.143111 0.121511 0.068365
Tirol 0.094781 0.437337 0.084568 0.169796 0.110267 0.143111 1.000000 0.104117 0.142133
Vorarlberg 0.052332 -0.055693 0.171228 0.153306 0.133786 0.121511 0.104117 1.000000 0.002764
Wien 0.216516 0.092613 0.310626 0.262978 0.131685 0.068365 0.142133 0.002764 1.000000